import Vue from 'vue'
import App from './App.vue'
import router from './router'
import $storage from './lib/storage'

import ant from 'ant-design-vue'
import 'ant-design-vue/dist/antd.min.css'
import $message from 'ant-design-vue/lib/message'

Vue.use(ant);

Vue.prototype.$storage = $storage;

Vue.config.productionTip = false;

$message.config({
  maxCount: 1
})

router.beforeEach((to, from, next) => {
  // 校验登陆
  if (to.meta.requireAuth !== false && !$storage.get($storage.keys.LOGIN_TOKEN)) {
    router.push({ path: '/login' })
    return
  }
  // 校验管理员
  // if (to.meta.requireAdmin && !Vue.prototype.$isAdmin()) {
  //   router.push({ path: '/404' })
  //   return
  // }
  // 设置标题
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
});


/**
 * 获取当前userId
 */
Vue.prototype.$getUserId = function() {
  try {
    return JSON.parse($storage.get($storage.keys.CURRENT_USER)).userId
  } catch (e) {
    return false
  }
};

new Vue({
  router,
  render: h => h(App)
}).$mount('#app');
